import request from "@/utils/request.ts";
import type { ConsultOrderPreData, Department, Image, PayParams, PartialConsult } from "@/types/consultTypes";
import type { ResponseType } from "@/types/responseTypes";
import type { ConsultOrderPreParams } from "@/types/consultTypes";
import type { ConsultOrderItem, EvaluateInfo } from "@/types/chitchat";

enum Enum {
    departmentList = "/dep/all",
    upload = "/upload",
    orderPre = "/patient/consult/order/pre",
    createOrder = "/patient/consult/order",
    order = "/patient/consult/pay",
    orderDetail = "/patient/consult/order/detail",
    prescriptionPic = "/patient/consult/prescription",
    evaluate = "/patient/order/evaluate"
}

/*获取科室列表的接口*/
export const fetchDepartmentListAPI = (): Promise<ResponseType<Department[]>> => request.get<Department, ResponseType<Department[]>>(Enum.departmentList);
/*上传文件图片的接口*/
export const uploadAPI = (data: FormData): Promise<ResponseType<Image>> => request.post<Image, ResponseType<Image>>(Enum.upload, data);
/*获取订单预支付的接口*/
export const fetchOrderPreAPI = (params: ConsultOrderPreParams): Promise<ResponseType<ConsultOrderPreData>> => request.get<ConsultOrderPreData, ResponseType<ConsultOrderPreData>>(Enum.orderPre, { params });
/*创建订单的接口*/
export const createConsultOrderAPI = (data: PartialConsult): Promise<ResponseType<{ id: string }>> => request.post<{ id: string }, ResponseType<{ id: string }>>(Enum.createOrder, data);
/*获取订单详情的接口*/
export const fetchConsultOrderDetailAPI = (orderId: string): Promise<ResponseType<ConsultOrderItem>> => request.get<ConsultOrderItem, ResponseType<ConsultOrderItem>>(Enum.orderDetail, { params: { orderId } });
/*支付接口*/
export const consultOrderPayAPI = (data: PayParams): Promise<ResponseType<{ payUrl: string }>> => request.post<{ payUrl: string }, ResponseType<{ payUrl: string }>>(Enum.order, data);
/*查看处方的接口*/
export const fetchPrescriptionPicAPI = (id: string): Promise<ResponseType<{ url: string }>> => request.get<{ url: string }, ResponseType<{ url: string }>>(`${Enum.prescriptionPic}/${id}`);

/*评价医生的接口*/
export const evaluateAPI = (data: EvaluateInfo): Promise<ResponseType<{ id: string }>> => request.post<{ id: string }, ResponseType<{ id: string }>>(Enum.evaluate, data);

